# coding:utf-8
# writingtime: 2022-6-27
# author: wanjun
# reference: 
# doi: 
# examiner:

import os
from Utilities.AutoGetOperator.selectionMethod.selectPackage import get_func

root_path = os.path.realpath(os.path.dirname(os.path.dirname(os.path.dirname(os.path.dirname(__file__)))))  # 度量方法所在目录
similarity_path = os.path.join(root_path,'Measure\similarity\getSimilarity.py')  # 相似度的文件路径
getSimilarity=get_func(similarity_path,'getSimilarity')  # 相似度函数的获取


def getSatisfactionWeight(matrix_list,q=3,si=0.6):
    '''

    :param matrix_list: 专家矩阵集
    :param q:
    :param si: 参数
    :return: 满意度专家权重
    '''

    length = len(matrix_list)
    m, n = len(matrix_list[0]), len(matrix_list[0][0])
    postive = ([1, 1], [0, 0])
    negative = ([0, 0], [1, 1])
    sum1_1 = 0
    sum2_2 = 0
    li = []
    for k in range(length):
        for i in range(m):
            for j in range(n):
                sum1_1 += getSimilarity([matrix_list[k][i][j]], [postive], q)
                sum2_2+=(1-getSimilarity([matrix_list[k][i][j]], [postive], q))

        li.append(((1-si)*sum1_1)/((1-si)*sum1_1+si*sum2_2))

    lis = [i / sum(li) for i in li]
    return lis


if __name__=='__main__':
    a1 = [
        [([0.85, 0.9], [0.15, 0.25]), ([0.75, 0.85], [0.2, 0.3]), ([0.75, 0.8], [0.25, 0.3]),
         ([0.7, 0.75], [0.3, 0.35]),
         ([0.6, 0.65], [0.4, 0.5])],
        [([0.9, 0.95], [0.1, 0.2]), ([0.8, 0.85], [0.15, 0.2]), ([0.75, 0.85], [0.2, 0.3]), ([0.75, 0.8], [0.25, 0.3]),
         ([0.65, 0.7], [0.35, 0.45])],
        [([0.8, 0.85], [0.15, 0.2]), ([0.75, 0.8], [0.25, 0.3]), ([0.7, 0.75], [0.35, 0.4]), ([0.65, 0.7], [0.35, 0.4]),
         ([0.6, 0.65], [0.35, 0.4])],
        [([0.75, 0.85], [0.2, 0.3]), ([0.7, 0.75], [0.25, 0.3]), ([0.65, 0.75], [0.2, 0.3]), ([0.6, 0.65], [0.3, 0.4]),
         ([0.6, 0.65], [0.3, 0.4])],
        [([0.7, 0.8], [0.2, 0.3]), ([0.7, 0.75], [0.3, 0.4]), ([0.6, 0.7], [0.3, 0.4]), ([0.6, 0.65], [0.4, 0.5]),
         ([0.5, 0.6], [0.45, 0.55])]]
    a2 = [
        [([0.8, 0.85], [0.2, 0.25]), ([0.75, 0.8], [0.25, 0.3]), ([0.7, 0.75], [0.25, 0.3]),
         ([0.65, 0.75], [0.25, 0.35]),
         ([0.6, 0.7], [0.3, 0.4])],
        [([0.85, 0.9], [0.1, 0.2]), ([0.75, 0.85], [0.2, 0.3]), ([0.7, 0.8], [0.25, 0.3]), ([0.7, 0.8], [0.2, 0.3]),
         ([0.6, 0.65], [0.35, 0.5])],
        [([0.75, 0.85], [0.2, 0.25]), ([0.75, 0.8], [0.2, 0.25]), ([0.65, 0.75], [0.25, 0.35]),
         ([0.65, 0.7], [0.25, 0.3]),
         ([0.55, 0.65], [0.4, 0.5])],
        [([0.75, 0.85], [0.25, 0.3]), ([0.7, 0.8], [0.2, 0.3]), ([0.7, 0.75], [0.3, 0.35]), ([0.65, 0.75], [0.3, 0.4]),
         ([0.6, 0.65], [0.4, 0.5])],
        [([0.75, 0.8], [0.25, 0.3]), ([0.7, 0.75], [0.35, 0.4]), ([0.65, 0.7], [0.35, 0.4]), ([0.6, 0.7], [0.4, 0.5]),
         ([0.55, 0.6], [0.4, 0.5])]]
    a3 = [
        [([0.75, 0.85], [0.15, 0.25]), ([0.75, 0.8], [0.2, 0.25]), ([0.7, 0.75], [0.25, 0.3]),
         ([0.65, 0.75], [0.3, 0.4]),
         ([0.55, 0.6], [0.45, 0.5])],
        [([0.8, 0.85], [0.15, 0.2]), ([0.75, 0.85], [0.2, 0.3]), ([0.75, 0.8], [0.25, 0.3]), ([0.7, 0.8], [0.2, 0.3]),
         ([0.6, 0.65], [0.4, 0.5])],
        [([0.75, 0.85], [0.2, 0.25]), ([0.7, 0.8], [0.2, 0.3]), ([0.7, 0.75], [0.35, 0.4]), ([0.65, 0.7], [0.35, 0.4]),
         ([0.6, 0.65], [0.35, 0.5])],
        [([0.75, 0.8], [0.2, 0.25]), ([0.7, 0.8], [0.25, 0.3]), ([0.7, 0.75], [0.3, 0.4]), ([0.65, 0.7], [0.3, 0.4]),
         ([0.5, 0.55], [0.45, 0.5])],
        [([0.75, 0.8], [0.2, 0.3]), ([0.7, 0.75], [0.2, 0.3]), ([0.65, 0.7], [0.35, 0.4]), ([0.6, 0.65], [0.35, 0.4]),
         ([0.55, 0.6], [0.45, 0.5])]]
    a4 = [
        [([0.8, 0.85], [0.1, 0.2]), ([0.75, 0.8], [0.2, 0.25]), ([0.7, 0.75], [0.25, 0.3]), ([0.65, 0.75], [0.3, 0.4]),
         ([0.5, 0.55], [0.45, 0.5])],
        [([0.85, 0.9], [0.15, 0.2]), ([0.8, 0.85], [0.15, 0.2]), ([0.75, 0.8], [0.25, 0.3]), ([0.7, 0.75], [0.2, 0.3]),
         ([0.65, 0.7], [0.3, 0.35])],
        [([0.75, 0.85], [0.2, 0.3]), ([0.75, 0.8], [0.25, 0.3]), ([0.65, 0.75], [0.3, 0.4]), ([0.65, 0.7], [0.35, 0.4]),
         ([0.55, 0.6], [0.45, 0.5])],
        [([0.75, 0.8], [0.25, 0.3]), ([0.7, 0.8], [0.25, 0.3]), ([0.7, 0.75], [0.35, 0.4]), ([0.65, 0.7], [0.35, 0.4]),
         ([0.55, 0.6], [0.4, 0.5])],
        [([0.7, 0.75], [0.2, 0.3]), ([0.65, 0.75], [0.3, 0.4]), ([0.6, 0.65], [0.4, 0.5]), ([0.55, 0.65], [0.5, 0.6]),
         ([0.45, 0.5], [0.5, 0.55])]]

    a_list=[a1,a2,a3,a4]
    q=3
    list1=[]
    print('参考正理想得到的权重',(getSatisfactionWeight(a_list, q)))
